function [sol, it] = newton(guess, lambda, ep, nx, ny, tol)
it = 0;
[n,w] = size(guess);
dr = ones(n,w);

while tol < norm(dr, 2)
    [jaco]=gen_j(guess, lambda, nx, ny);
    [R] = gen_r(guess, lambda, ep, nx, ny);
    dr = (R\jaco)';
    guess = guess + dr;
    it = it +1;
end
sol = guess;